use "INSERTPATH\mainstudy.dta", clear
cd "INSERTPATH\results"



*************************************************************************************************************
****************************************** MAIN PAPER *********************************************************
*************************************************************************************************************

****Manipulation of dominance (noted in section 4.1)
ttest TJ_Dominance, by(Undemocratic)
ttest TJ_domi_recall, by(Undemocratic)

****Manipulation check (context) (noted in section 4.1)
reg think_China ib1.Context
reg think_Russia ib2.Context
reg think_Peace i.Context



*****FIGURE 2*****
*Panel A
reg TJ_capability i.Undemocratic##i.contextbinary
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) yline(0) ///
  xtitle("{bf:Difference = .09 [95% CI: .05-.14]}", size(medlarge))  ytitle("Effect of Undemocratic Behavior", size(large)) plot1opts(bcolor(gs6)) ci1opt(color(gs6*2)) title("Rated Capability", size(large)) xlabel(,labsize(medlarge))
graph save capability_main, replace

reg TJ_voteintention i.Undemocratic##i.contextbinary
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) yline(0) ///
xtitle("{bf:Difference = .08 [95% CI: .04-.13]}", size(medlarge))  ytitle("Effect of Undemocratic Behavior", size(large)) plot1opts(bcolor(gs6)) ci1opt(color(gs6*2)) title("Vote Intentions", size(large)) xlabel(,labsize(medlarge))
graph save vote_main, replace

graph combine capability_main.gph vote_main.gph, title("{bf: A: Undemocratic Behavior}", size(medlarge))
graph save main, replace

*Panel B
reg TJ_capability c.TJ_domi_recall##i.contextbinary
margins, dydx(TJ_domi_recall) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.4(.2).4) recast(bar) yline(0) ///
  xtitle("{bf:Difference = .31 [95% CI: .19-.42]}", size(medlarge))  ytitle("Dominance-Capability Correlation", size(large)) plot1opts(bcolor(gs11)) ci1opt(color(gs11*2)) title("Rated Capability", size(large)) xlabel(,labsize(medlarge))
graph save capability_mecha, replace

reg TJ_voteintention c.TJ_domi_recall##i.contextbinary
margins, dydx(TJ_domi_recall) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.4(.2).4) recast(bar) yline(0) ///
xtitle("{bf:Difference = .27 [95% CI: .14-.40]}", size(medlarge))  ytitle("Dominance-Vote Correlation", size(large)) plot1opts(bcolor(gs11)) ci1opt(color(gs11*2)) title("Vote Intentions", size(large)) xlabel(,labsize(medlarge))
graph save vote_mecha, replace

**Combine
graph combine capability_mecha.gph vote_mecha.gph, title("{bf:B: Dominance}", size(medlarge))
graph save mecha, replace

graph combine main.gph mecha.gph, row(2)  imargin(medlarge)
graph display, ysize(8) xsize(6)
graph export study2.pdf, replace






******************FIGURE 3: Effects by partisanship******************
reg TJ_capability i.Undemocratic##i.contextbinary if partyid == 1
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) plot1opts(bcolor(navy*1.2)) ci1opt(color(navy*2.4)) yline(0) ///
xtitle("{bf:Difference = .05 [95% CI: -.01-.12]}", size(small))  ytitle("") title("Rated Capability") 
graph save capability_dems, replace

reg TJ_capability i.Undemocratic##i.contextbinary if partyid == 2
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) plot1opts(bcolor(red*1.6)) ci1opt(color(red*3)) yline(0) ///
xtitle("{bf:Difference = .16 [95% CI: .09-.23]}", size(small))  ytitle("") title("Rated Capability")
graph save capability_reps, replace

reg TJ_capability i.Undemocratic##i.contextbinary if partyid == 3
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) plot1opts(bcolor(gs9)) ci1opt(color(gs9*2)) yline(0) ///
xtitle("{bf:Difference = .08 [95% CI: .01-.16]}", size(small))  ytitle("") title("Rated Capability")
graph save capability_independents, replace

reg TJ_voteintention i.Undemocratic##i.contextbinary if partyid == 1
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) plot1opts(bcolor(navy*1.2)) ci1opt(color(navy*2.4)) yline(0) ///
xtitle("{bf:Difference = .04 [95% CI: -.03-.11]}", size(small))  ytitle("") title("Vote Intentions")
graph save vote_dems, replace

reg TJ_voteintention i.Undemocratic##i.contextbinary if partyid == 2
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) plot1opts(bcolor(red*1.6)) ci1opt(color(red*3)) yline(0) ///
xtitle("{bf:Difference = .15 [95% CI: .07-.23]}", size(small))  ytitle("") title("Vote Intentions")
graph save vote_reps, replace

reg TJ_voteintention i.Undemocratic##i.contextbinary if partyid == 3
margins, dydx(Undemocratic) at(contextbinary= (0 1))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) plot1opts(bcolor(gs9)) ci1opt(color(gs9*2)) yline(0) ///
xtitle("{bf:Difference = .11 [95% CI: .03-.20]}", size(small)) ytitle("") title("Vote Intentions")
graph save vote_independents, replace

* Combine
graph combine capability_dems.gph vote_dems.gph, title("{bf:A: Democrats}") row(2)
graph save dems, replace
graph combine capability_independents.gph vote_independents.gph, title("{bf:B: Independents}") row(2)
graph save independents, replace
graph combine capability_reps.gph vote_reps.gph, title("{bf:C: Republicans}") row(2)
graph save reps, replace

graph combine dems.gph independents.gph reps.gph, l1title("Effect of Undemocratic Behavior", size(small)) row(1)
graph export partisanship.pdf, replace






*******FIGURE E1: ROBUSTNESS WITH CONTEXT SPLIT****************
reg TJ_capability i.Undemocratic##i.Context 
margins, dydx(Undemocratic) at(Context= (0 1 2))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) yline(0) ///
xtitle("")  ytitle("Effect of Undemocratic Behavior", size(large)) title("Rated Capability", size(large)) xlabel(,labsize(med))
graph save capability_main_robust, replace

reg TJ_voteintention i.Undemocratic##i.Context
margins, dydx(Undemocratic) at(Context= (0 1 2))
marginsplot,  recastci(rcap) yscale(range(-.3(.1).1)) ylabel(-.3(.1).1) recast(bar) yline(0) ///
xtitle("")  ytitle("Effect of Undemocratic Behavior", size(large)) title("Vote Intentions", size(large)) xlabel(,labsize(med))
graph save vote_main_robust, replace

graph combine capability_main_robust.gph vote_main_robust.gph, title("{bf: Robustness to Splitting Conflict Contexts}", size(medlarge))
graph save main_robust, replace
graph export main_robust.pdf, replace


*******(ENTRIES FOR) FIGURE F1: SEM analyses: Testing if undemocratic behavior affects TJ rating through dominace inference *********

***** Analyses for CONTROL condition:
** DV: Thomas Johnson's capabilities 
sem (Undemocratic -> TJ_domi_recall) ///
	(Undemocratic TJ_domi_recall -> TJ_capability) if contextbinary == 0, nocapslatent
	
estat teffects
estat gof, stats(all)


** DV: Likelihood to vote for Thomas Johnson
sem (Undemocratic -> TJ_domi_recall) ///
	(Undemocratic TJ_domi_recall -> TJ_voteintention) if contextbinary == 0, nocapslatent
	
estat teffects
estat gof, stats(all)



***** Analyses for CONFLICT condition:
** DV: Thomas Johnson's capabilities 
sem (Undemocratic -> TJ_domi_recall) ///
	(Undemocratic TJ_domi_recall -> TJ_capability) if contextbinary == 1, nocapslatent
	
estat teffects
estat gof, stats(all)

** DV: Likelihood to vote for Thomas Johnson
sem (Undemocratic -> TJ_domi_recall) ///
	(Undemocratic TJ_domi_recall -> TJ_voteintention) if contextbinary == 1, nocapslatent
	
estat teffects
estat gof, stats(all)